package com.cosina.util.ep.findjar.view;


import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile;


public class FindJarViewTest{
	
	public static void main(String[] args){
		System.out.println(find("org.apache.ws.commons.schema.resolver.URIResolver","E:\\workspaces4current\\sceworkspace\\ste_1.3\\lib"));
	}
	
	public static File find(String className, String dirString){
		if(null == className || dirString == null){
			throw new IllegalArgumentException("arg is not valid ");
		}
		className = className.replace("\\", "/").replace('.', '/') + ".class";
		File dir= new File(dirString);
		
		for(File eachJar : dir.listFiles()){
			if(eachJar.isFile()== false)
				continue;
			
			String name = eachJar.getName();
			try {
				if(name.endsWith("zip") || name.endsWith("jar") ){
					if(find(new JarFile(eachJar),className))
						return eachJar;
				}
			} catch (IOException e) {
				e.printStackTrace();
				throw new IllegalArgumentException(e.getMessage());
			}
		}
		return null;
	}

	private static  boolean find(JarFile dir, String className){
		return null != dir.getJarEntry(className);
	}
}